//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_clienthd.sqf"
#include "xr_macros.sqf"

#define __shots ["shotBullet","shotShell","shotRocket","shotMissile","shotTimeBomb","shotMine","shotGrenade","shotSpread","shotSubmunitions","shotDeploy","shotBoundingMine","shotDirectionalBomb"]

private ["_unit", "_part", "_dam", "_injurer", "_ammo"];
PARAMS_5(_unit,_part,_dam,_injurer,_ammo);
__TRACE_1("","_this");
if (!alive _unit || {_dam == 0}) exitWith {
	__TRACE_1("exiting, unit dead or healing","_dam");
	_dam
};
if (__GV(_unit,GVARXR(pluncon)) || {GVARXR(phd_invulnerable)}) exitWith {
	__TRACE_2("exiting, unit uncon or invulnerable","_part");
	0
};
if (d_no_teamkill == 0 && {_dam >= 0.1} && {!isNull _injurer} && {isPlayer _injurer} && {_injurer != _unit} && {vehicle _unit == _unit} && {side (group _injurer) == side (group _unit)}) exitWith {
	if (_part == "" && {_ammo != ""} && {getText (configFile/"CfgAmmo"/_ammo/"simulation") in __shots} && {time > (__pGetVar(d_tk_cutofft) + 3)}) then {
		_unit setVariable ["d_tk_cutofft", time];
		hint format [(localize "STR_DOM_MISSIONSTRING_497"), name _injurer];
		["d_unit_tkr", [_unit,_injurer]] call d_fnc_NetCallEventCTS;
		if (d_domdatabase) then {
			["d_ptkkg", _injurer] call d_fnc_NetCallEventCTS;
		};
	};
	0
};
if (_dam >= 0.9 && {time > (_unit getVariable QGVARXR(last_gear_save))}) then {
	__TRACE_1("saving respawn gear","_dam");
	_unit setVariable [QGVARXR(last_gear_save), time + 2];
	call d_fnc_save_respawngear;
	_unit setVariable [QGVARXR(isleader), leader (group player) == player];
	GVARXR(pl_group) = group player;
};
BIS_hitArray = _this; BIS_wasHit = true;
_dam